﻿@using OSBLE.Models.Assignments
@using OSBLE.Areas.AssignmentDetails.ViewModels
@using OSBLE.Models.Courses;
@using OSBLE.Resources
@model AssignmentDetailsViewModel
@{
    ViewBag.Title = "Assignment Details";
    DynamicDictionary headerData = Model.HeaderBuilder.BuildHeader(Model.CurrentAssignment);
    Layout = "~/Views/Shared/_Layout.cshtml";
    List<Assignment> assignmentList = new List<Assignment>();
        
}
@section Header
{
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/json2.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/AssignmentDetails/Content/js/Home.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/AssignmentDetails/Content/css/Home.css")" type="text/css" rel="Stylesheet" />
    @RenderSection("Header", false)
}
<h1>@Model.CurrentAssignment.AssignmentName.ToFirstCharUpper()     

</h1>

<script type="text/javascript">

    $(document).ready(function () {
        $('#changeAssignment').change(function () {
            var assignmentNumber = $('#changeAssignment').val();
            window.location.replace("/AssignmentDetails/" + assignmentNumber);

        });
    });
</script>

@*If student, then remove all assignments that have not been published from the assignment list
  If a moderator, remove all assignments as its hard to distinguish which should be available
*@
@if (Model.Client.AbstractRole.CanSubmit)
{
    assignmentList = assignmentList.Where(a => a.IsDraft == false).ToList();
}
else if(Model.Client.AbstractRoleID == (int)CourseRole.CourseRoles.Moderator)
{
    assignmentList = null;
}
else
{
    assignmentList = (Model.Client.AbstractCourse as Course).Assignments.OrderBy(a => a.AssignmentName).ToList();
}

@if (assignmentList != null && assignmentList.Count > 1)
{
    <table>
            <tr>
                <th>Select Assignment:</th>
                <td>
                    <select id="changeAssignment">
                        @foreach (Assignment assignment in assignmentList)
                        {
                            
                            @*generating select box*@
                            string optionText = "<option value=\"{0}\"{1}>{2}</option>";
                            string selectValue = "";
                            if (Model.CurrentAssignment.ID == assignment.ID)
                            {
                                selectValue = "selected=\"selected\"";
                            }
                            @Html.Raw(String.Format(optionText, assignment.ID, selectValue, assignment.AssignmentName));
                            
                        }
                    </select>
                </td>
            </tr>
        </table>
}

@if (Model.Client.AbstractRole.CanModify)
{
    <ul id="AssignmentLinksList">
        <li>
            @{string actionUrl = Url.Action(
                                    "ToggleDraft",
                                    "Home",
                                    new
                                    {
                                        assignmentId = Model.CurrentAssignment.ID
                                    }
                                   );
              string linkTitle = "Unpublish Assignment";
              HelperResult linkImg = Helpers.UnPublishButton();
            }
            @if (Model.CurrentAssignment.IsDraft == true)
            {
                linkTitle = "Publish Assignment";
                linkImg = Helpers.PublishButton();
            }
            <a href="@actionUrl" title="@linkTitle">@Html.Raw(linkImg.ToHtmlString())</a>
        </li>
            <li><a title="Click to Edit" href="@Url.Action("Index", "Home", new { area = "AssignmentWizard", assignmentId = Model.CurrentAssignment.ID })">@Helpers.EditButton()</a>
            </li>
        <li>
            @{
            string deleteLink = Url.Action("DeleteAssignment", new { assignmentId = Model.CurrentAssignment.ID });
            }
            <a 
        id="DeleteAssignmentLink"
        title="Click to Delete" 
        class="pointerOnMouseOver" 
        href="@deleteLink"
        >@Helpers.DeleteButton()</a> </li>
    </ul>
}
<table id="AssignmentDetailsTable">
    <tr id="AssignmentDetailsTableFirstRow">
        <th>
            Description:
        </th>
        <td>
            @Html.Raw(HttpUtility.HtmlDecode(Helpers.WikiUrlLinking(Model.CurrentAssignment.AssignmentDescription).ToString()))
        </td>
    </tr>
    <tr>
        <th>
            Type:
        </th>
        <td>@Model.CurrentAssignment.Type.Explode()
        </td>
    </tr>
    <tr>
        <th>
            Released:
        </th>
            <td>
                @Model.CurrentAssignment.ReleaseDate
            </td>
    </tr>
    @RenderSection("AssignmentDetails", true)
</table>
@if (Model.Client.AbstractRole.CanGrade)
{
    <table  id="StudentsTable">
        <tr>
            <th>
                Name
            </th>
            @foreach (string key in Model.TableColumnHeaders.Keys)
            {
                <th>@Model.TableColumnHeaders[key]
                </th>
            }
        </tr>
        @RenderSection("TableData", false)
    </table>
    
    <!--Element for modal confirmation box-->
    <div id="confirmDeleteWindow" style="display: none;" title="Delete Assignment">
        <div id="confirmForm">
            Are you sure you want to delete this assignment?
            @using (Html.BeginForm("DeleteAssignment", "Home", new { assignmentId = Model.CurrentAssignment.ID }, FormMethod.Post))
            {
                <div class="yesAndNoDiv">
                    <input value="Delete" type="submit" />
                    <input value="Cancel" type="button" onclick="hideConfirmDeleteWindow()" />
                </div>
            }
        </div>
    </div>
    
}
else
{
    //AC: should never use, but required by MVC3 to render
    <text>@RenderSection("TableData", false)</text>
}